package com.ruoyi.web.controller.car;

import com.ruoyi.car.domain.CatRepair;
import com.ruoyi.car.domain.CatUpkeep;
import com.ruoyi.car.service.ICatUpkeepService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-06-24
 */
@Controller
@RequestMapping("/ruoyi/upkeeplead")
public class CatUpkeepLeadController extends BaseController
{
    private String prefix = "ruoyi/upkeep";

    @Autowired
    private ICatUpkeepService catUpkeepService;

    @RequiresPermissions("ruoyi:upkeeplead:view")
    @GetMapping()
    public String upkeep()
    {
        return prefix + "/leadupkeep";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("ruoyi:upkeeplead:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CatUpkeep catUpkeep)
    {
        startPage();
        List<CatUpkeep> list = catUpkeepService.selectCatUpkeepList(catUpkeep);
        list.removeIf(catUpkeep1 -> catUpkeep1.getcStatus()==0);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("ruoyi:upkeeplead:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CatUpkeep catUpkeep)
    {
        List<CatUpkeep> list = catUpkeepService.selectCatUpkeepList(catUpkeep);
        ExcelUtil<CatUpkeep> util = new ExcelUtil<CatUpkeep>(CatUpkeep.class);
        return util.exportExcel(list, "upkeep");
    }



    /**
     * 通过申请
     */
    @RequiresPermissions("ruoyi:upkeeplead:consent")
    @Log(title = "请假业务", businessType = BusinessType.UPDATE)
    @PostMapping( "/consent")
    @ResponseBody
    public AjaxResult consent(Long id, CatUpkeep catUpkeep) {
        catUpkeep.setcId(id);
        catUpkeep.setcStatus(4L);
        int leave = catUpkeepService.updateCatUpkeep(catUpkeep);
        return success();
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{cId}")
    public String edit(@PathVariable("cId") Long cId, ModelMap mmap)
    {
        CatUpkeep catUpkeep = catUpkeepService.selectCatUpkeepById(cId);
        mmap.put("catUpkeep", catUpkeep);
        return prefix + "/leadedit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("ruoyi:upkeeplead:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CatUpkeep catUpkeep)
    {
        catUpkeep.setcStatus(3L);
        return toAjax(catUpkeepService.updateCatUpkeep(catUpkeep));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("ruoyi:upkeeplead:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(catUpkeepService.deleteCatUpkeepByIds(ids));
    }

    @RequiresPermissions("ruoyi:upkeep:removes")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/removes")
    @ResponseBody
    public AjaxResult removes(Long id)
    {
        int succ= catUpkeepService.deleteCatUpkeepById(id);
        if(succ==1){
            return success("撤销成功");
        }else{
            return error("撤销失败");
        }

    }


    /**
     * 查询车辆保养列表
     */
    @RequiresPermissions("ruoyi:upkeeplead:lists")
    @PostMapping("/lists/{cId}")
    @ResponseBody
    public TableDataInfo lists(@PathVariable("cId") Long cId)
    {
        startPage();
        List<CatUpkeep> lists = catUpkeepService.selectCarUpKeepManagesList(cId);
        return getDataTable(lists);
    }
    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("ruoyi:upkeeplead:exportrepair")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/exportrepair")
    @ResponseBody
    public AjaxResult exportCar(CatUpkeep catUpkeep)
    {
        List<CatUpkeep> list = catUpkeepService.selectCat(catUpkeep);
        ExcelUtil<CatUpkeep> util = new ExcelUtil<CatUpkeep>(CatUpkeep.class);
        return util.exportExcel(list, "车辆保养支出");
    }
}
